package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.OrrDeviceOperatorStatusMapper;
import com.yunhai.device.service.OrrDeviceOperatorStatusService;
import com.yunhai.model.entity.orr.OrrDeviceOperatorStatusEntity;
import com.yunhai.model.vo.orr.OrrDeviceOperatorStatusQuery;
import com.yunhai.model.vo.orr.OrrDeviceOperatorStatusVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OrrDeviceOperatorStatusServiceImpl implements OrrDeviceOperatorStatusService {

    @Resource
    private OrrDeviceOperatorStatusMapper orrDeviceOperatorStatusMapper;

    /**
     * 获取 OrrDeviceOperatorStatus 分页列表
     */
    @Transactional
    public IPage getOrrDeviceOperatorStatusPagination(PaginationVo paginationVo, OrrDeviceOperatorStatusQuery orrDeviceOperatorStatusQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<OrrDeviceOperatorStatusEntity> lqs = new LambdaQueryWrapper();
        orrDeviceOperatorStatusMapper.selectPage(page, lqs);

        List<OrrDeviceOperatorStatusEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return page;
    }


    /**
     * 获取 OrrDeviceOperatorStatus 所有数据
     *
     */
    @Transactional
    public List<OrrDeviceOperatorStatusEntity> getOrrDeviceOperatorStatusAllList( OrrDeviceOperatorStatusQuery orrDeviceOperatorStatusQuery ) throws Exception {

        LambdaQueryWrapper<OrrDeviceOperatorStatusEntity> lqs = new LambdaQueryWrapper();
        List<OrrDeviceOperatorStatusEntity> list = orrDeviceOperatorStatusMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 OrrDeviceOperatorStatus 详情
     */
    @Transactional
    public OrrDeviceOperatorStatusEntity getOrrDeviceOperatorStatusDetail( Long id) throws Exception {

        OrrDeviceOperatorStatusEntity orrDeviceOperatorStatusEntity = orrDeviceOperatorStatusMapper.selectById(id);
        return orrDeviceOperatorStatusEntity;
    }


    /**
     * 新增 OrrDeviceOperatorStatus
     * */
    @Transactional
    public void addOrrDeviceOperatorStatus(OrrDeviceOperatorStatusVo orrDeviceOperatorStatusVo) throws Exception {

        OrrDeviceOperatorStatusEntity orrDeviceOperatorStatusEntity = new OrrDeviceOperatorStatusEntity();
        ReflectionCopy.copyProperties( orrDeviceOperatorStatusEntity, orrDeviceOperatorStatusVo );
        orrDeviceOperatorStatusMapper.insert(orrDeviceOperatorStatusEntity);
        return;
    }


    /**
     * 更新 OrrDeviceOperatorStatus
     * */
    @Transactional
    public void updateOrrDeviceOperatorStatus( OrrDeviceOperatorStatusVo orrDeviceOperatorStatusVo) throws Exception {

        if( orrDeviceOperatorStatusVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        OrrDeviceOperatorStatusEntity orrDeviceOperatorStatusEntity = new OrrDeviceOperatorStatusEntity();
        ReflectionCopy.copyProperties( orrDeviceOperatorStatusEntity, orrDeviceOperatorStatusVo );
        orrDeviceOperatorStatusMapper.updateById(orrDeviceOperatorStatusEntity);
        return;
    }

    /**
     * 删除 OrrDeviceOperatorStatus
     * */
    @Transactional
    public void batchRemoveOrrDeviceOperatorStatus( List<Long> ids ) throws Exception {

        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        orrDeviceOperatorStatusMapper.deleteBatchIds(ids);
    }

}